package main.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public abstract class Component {
	
	private List<Attribute> attributes = new ArrayList<Attribute>();
	private List<Attribute> idAttributes = new ArrayList<Attribute>();
	
	private String name;
	
	public Component(){
		this.attributes = new ArrayList<Attribute>();
		this.idAttributes = new ArrayList<Attribute>();
	}
	
	public Component(String name){
		this.setName(name);
		this.attributes = new ArrayList<Attribute>();
		this.setIdAttributes(new ArrayList<Attribute>());
	}

	public void addAttribute(Attribute attribute){
		this.attributes.add(attribute);
		attribute.setParent(this);
	}
	
	public void addIdAttribute(Attribute attribute){
		this.idAttributes.add(attribute);
		attribute.setParent(this);
	}

	public void removeAllAttributes(){
		this.attributes = new ArrayList<Attribute>();
		this.idAttributes = new ArrayList<Attribute>();
	}
	
	public Boolean removeIdAttribute(Attribute att){
		return this.attributes.remove(att);
	}
	
	public Boolean removeAttribute(Attribute att){
		return this.attributes.remove(att);
	}
	
	public Attribute getAttribute(Attribute attribute) {
		Iterator<Attribute> itr = attributes.iterator();
		Attribute attr_result = null;
		while (itr.hasNext()) {
			Attribute element = itr.next();
			if ( element.getName().compareTo(attribute.getName()) == 0 ){
				attr_result = element;
			}
		}
		
		return attr_result;
	}
	
	public Attribute getAttribute(String att_name) {
		Iterator<Attribute> itr = attributes.iterator();
		Attribute attr_result = null;
		while (itr.hasNext()) {
			Attribute element = itr.next();
			if ( element.getName().compareTo(att_name) == 0 ){
				attr_result = element;
			}
		}
		return attr_result;
	}
	
	public List<Attribute> getAttributes(){
		return this.attributes;
	}

	public void setAttributes(List<Attribute> attributes) {
		this.attributes = attributes;
	}

	public List<Attribute> getIdAttributes() {
		return idAttributes;
	}

	public void setIdAttributes(List<Attribute> idAttributes) {
		this.idAttributes = idAttributes;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Boolean isEntity(){
		return Boolean.FALSE;
	}
	
	public Boolean isRelation(){
		return Boolean.FALSE;
	}
	
	public Boolean isAttribute(){
		return Boolean.FALSE;
	}

	public boolean isHierarchy() {
		return Boolean.FALSE;
	}
	
	
	public boolean equals(Object arg0) {
	
		return (name.compareToIgnoreCase(((Component)arg0).getName()) == 0);
	}

}
